#include <cstdio>

int a[ 200001 ], f[ 200001 ], t[ 200001 ][ 2 ], n, m;

int max( int x1, int x2 ) { return ( x1 < x2 )? x2: x1; }

void init( )
{
    int i, j;
    for ( i = 0; i < n; i++ )
        for ( j = 0; j < m; j++ )
            scanf("%d", &a[ i * m + j ]);
}

void work( )
{
    int i, j, maxn;
    for ( i = 0; i < n; i++ )
    {
        t[ 0 ][ 0 ] = 0;
        t[ 0 ][ 1 ] = a[ i * m ];
        for ( j = 1; j < m; j++ )
        {
            t[ j ][ 0 ] = max( t[ j - 1 ][ 0 ], t[ j - 1 ][ 1 ] );
            t[ j ][ 1 ] = t[ j - 1 ][ 0 ] + a[ i * m + j ];
        }
        if ( i == 0 || i == 1 )
            f[ i ] = max( t[ m - 1 ][ 0 ], t[ m - 1 ][ 1 ] );
        else
        {
            maxn = 0;
            for ( j = 0; j < i - 1; j++ )
                if ( maxn < f[ j ] )
                    maxn = f[ j ];
            f[ i ] = max( t[ m - 1 ][ 0 ], t[ m - 1 ][ 1 ] ) + maxn;
        }
    }
    if ( n > 1 )
        printf("%d\n", max( f[ n - 1 ], f[ n - 2 ] ));
    else
        printf("%d\n", f[ n - 1 ]);
}

int main( )
{
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        init( );
        work( );
    }
    return 0;
}
